package ui.tools;

import java.awt.Point;
import java.awt.event.InputEvent;

import board.NodeMark;
import board.SimpleMark;

import ui.EditController;

/**
 * EditTool for adding territory marks.
 * @author TKington
 *
 */
public class TerritoryTool extends EditTool {
	@Override
	public boolean mouseClicked(int x, int y, int modifiers) {
		EditController controller = EditController.instance();
		
		int type;
		if((modifiers & InputEvent.BUTTON1_MASK) != 0)
			type = NodeMark.TERRB;
		else type = NodeMark.TERRW;
		
		SimpleMark m = controller.getSimpleMark(x, y);
		if(m != null)
			controller.removeMark(m);
		
		int oldtype = -1;
		if(m != null)
			oldtype = m.getType();
		if(oldtype != type)
			controller.addMark(new SimpleMark(type, new Point(x, y)));
		
		return true;
	}
}
